<template>
	<div class="widgets bg-white small">
        <div class="left">
    		<el-radio-group v-model="status['default']" size="small" @change="changeStatus">
                <el-radio-button v-for="item in status['children']" :label="item['name']" :key="item['id']"></el-radio-button>
            </el-radio-group>
        </div>
        <div class="right">
            <el-date-picker v-model="startTime" type="date" placeholder="开始时间" size="small" value-format="yyyy-MM-dd" :picker-options="startDatePicker" style="margin-left:10px;"></el-date-picker>
            <span style="margin: 0 5px;">到</span>
            <el-date-picker v-model="endTime" type="date" placeholder="结束时间" size="small" value-format="yyyy-MM-dd" :picker-options="endDatePicker"></el-date-picker>
            <el-input v-model="searchText" class="search__input" placeholder="输入搜索内容" style="margin-left: 10px!important;"></el-input>
            <el-button type="primary">查询</el-button>
        </div>
	</div>
</template>
<script>
import status from './status.json'
export default {
	data() {
		return {
			searchText: '',
			startTime:'',       //起始时间
            endTime:'',         //结束时间
            startDatePicker: this.validateStartDate(),      //校验开始时间
            endDatePicker: this.validateEndDate(),          //校验结束时间
            status: status,     //按钮状态组
		}
	},
	methods: {
		validateStartDate() {
            return {
                disabledDate(time){
                    return time.getTime() > Date.now()          //开始时间小于等于当天
                }
            }
        },
        validateEndDate() {             //结束时间
            let that = this;
            return {
                disabledDate(time) {
                    if(that.startTime){
                        return new Date(that.startTime).getTime() - 86400000 > time.getTime() || time.getTime() > Date.now()
                    }else{
                        return time.getTime() > Date.now()      //开始时间不选时，结束时间最大值小于等于当天
                    }
                }
            }
        },
        changeStatus(name) {          //改变状态
            let status = this.status;
            status['children'].forEach(item => {
                if(item['name'] === name) {
                    this.$store.commit('borrowApproveOrderStore/updateStatus', item['status']);
                    this.$store.dispatch('borrowApproveOrderStore/getOrderTableDataByBtnStutas', item['url']);
                }
            });
        }
	}
}
</script>